package com.qf.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsAddressMapper;
import com.qf.pojo.DtsAddress;
import com.qf.service.DtsAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;


@Service
public class DtsAddressServiceImpl implements DtsAddressService {

    @Autowired
    private DtsAddressMapper dtsAddressMapper;

    @Override
    public IPage<DtsAddress> selectList(Integer page, Integer limit,Integer userId,String name, String sort, String order) {

        IPage<DtsAddress> iPage = new Page<>(page, limit);

        QueryWrapper<DtsAddress> wrapper = new QueryWrapper<>();
        wrapper.eq("deleted", false);
        wrapper.orderByAsc("asc".equalsIgnoreCase(order),sort);
        wrapper.orderByDesc("desc".equalsIgnoreCase(order),sort);
        wrapper.eq(userId != null, "id", userId);
        wrapper.like(!StringUtils.isEmpty(name), "name", name);
        IPage<DtsAddress> result = dtsAddressMapper.selectPage(iPage, wrapper);
        return result;
    }
}
